Please tell me how to disable the default domain for Amplify Hosting.
The issue
I am using a custom domain with Amplify Hosting.
I want to restrict access to my application to only the custom domain, so please tell me how to disable the default domain amplifyapp.com.
The solution
The default domain amplifyapp.com for Amplify Hosting cannot be disabled.
As an alternative, please consider redirecting access from the default domain to the custom domain.
Redirects enable a web server to reroute navigation from one URL to another.
I tried it
I will try redirecting from the default domain amplifyapp.com to the custom domain.
The application used with Amplify Hosting has been pushed to CodeCommit.
Additionally, the custom domain to be used is an-makoto.site.
First, I will confirm that I can access the application using the default domain amplifyapp.com.
I was able to access the application using the default domain URL.
Next, I will register the custom domain.
The domain I am using this time was obtained outside of AWS and has been registered in a Route 53 hosted zone.
Once registered, domain verification will begin, so I will wait for a while.
After the custom domain registration is complete, I will confirm that I can access the application using the custom domain as well.
I was able to access the application using the custom domain as well.
Now, I will configure the settings to redirect from the default domain amplifyapp.com to the custom domain an-makoto.site.
In the Amplify console, click on "Rewrites and redirects" from the left sidebar.
Click on "Manage redirects".
Configure the settings as follows:
- Source address: Default domain URL
- Target address: Custom domain URL
- Type: 301 (Redirect - Permanent)
After configuring the redirect settings, access the default domain URL and confirm that it redirects to the custom domain URL.
$ curl https://main.d1lbshw0w1wpb0.amplifyapp.com -sLI | grep location
location: https://an-makoto.site/
Please note that the redirect settings are evaluated in order from top to bottom.
Redirects are applied from the top of the list down.